package cn.lijiancn01.demo.system.codegen;

import cn.hutool.db.meta.JdbcType;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.LinkedHashMap;
import java.util.Map;

import static cn.hutool.db.meta.JdbcType.BIGINT;
import static cn.hutool.db.meta.JdbcType.BINARY;
import static cn.hutool.db.meta.JdbcType.BIT;
import static cn.hutool.db.meta.JdbcType.BLOB;
import static cn.hutool.db.meta.JdbcType.BOOLEAN;
import static cn.hutool.db.meta.JdbcType.CHAR;
import static cn.hutool.db.meta.JdbcType.CLOB;
import static cn.hutool.db.meta.JdbcType.DATE;
import static cn.hutool.db.meta.JdbcType.DECIMAL;
import static cn.hutool.db.meta.JdbcType.DOUBLE;
import static cn.hutool.db.meta.JdbcType.FLOAT;
import static cn.hutool.db.meta.JdbcType.INTEGER;
import static cn.hutool.db.meta.JdbcType.LONGVARBINARY;
import static cn.hutool.db.meta.JdbcType.LONGVARCHAR;
import static cn.hutool.db.meta.JdbcType.NCHAR;
import static cn.hutool.db.meta.JdbcType.NCLOB;
import static cn.hutool.db.meta.JdbcType.NUMERIC;
import static cn.hutool.db.meta.JdbcType.NVARCHAR;
import static cn.hutool.db.meta.JdbcType.REAL;
import static cn.hutool.db.meta.JdbcType.SMALLINT;
import static cn.hutool.db.meta.JdbcType.TIME;
import static cn.hutool.db.meta.JdbcType.TIMESTAMP;
import static cn.hutool.db.meta.JdbcType.TINYINT;
import static cn.hutool.db.meta.JdbcType.VARBINARY;
import static cn.hutool.db.meta.JdbcType.VARCHAR;

public class JavaProperty {
    private static Map<JdbcType, Class<?>> javaPropertyMap = new LinkedHashMap<>();

    static {
        //Number
        javaPropertyMap.put(INTEGER, Integer.class);
        javaPropertyMap.put(SMALLINT, Short.class);
        javaPropertyMap.put(BIGINT, Long.class);
        //BigDecimal
        javaPropertyMap.put(REAL, BigDecimal.class);
        javaPropertyMap.put(FLOAT, BigDecimal.class);
        javaPropertyMap.put(DOUBLE, BigDecimal.class);
        javaPropertyMap.put(NUMERIC, BigDecimal.class);
        javaPropertyMap.put(DECIMAL, BigDecimal.class);
        //String
        javaPropertyMap.put(CHAR, String.class);
        javaPropertyMap.put(VARCHAR, String.class);
        javaPropertyMap.put(LONGVARCHAR, String.class);
        javaPropertyMap.put(NVARCHAR, String.class);
        javaPropertyMap.put(NCHAR, String.class);
        javaPropertyMap.put(NCLOB, String.class);
        javaPropertyMap.put(TINYINT, String.class);
        javaPropertyMap.put(BINARY, String.class);
        javaPropertyMap.put(VARBINARY, String.class);
        javaPropertyMap.put(LONGVARBINARY, String.class);
        javaPropertyMap.put(CLOB, String.class);
        javaPropertyMap.put(BLOB, String.class);
        //时间
        javaPropertyMap.put(DATE, LocalDateTime.class);
        javaPropertyMap.put(TIME, LocalDateTime.class);
        javaPropertyMap.put(TIMESTAMP, LocalDateTime.class);
        //布尔
        javaPropertyMap.put(BOOLEAN, Boolean.class);
        javaPropertyMap.put(BIT, boolean.class);
    }

    public static void register(JdbcType jdbcType, Class<?> propertyTypeClz) {
        javaPropertyMap.put(jdbcType, propertyTypeClz);
    }

    public static Class<?> getPropertyTypeClz(JdbcType jdbcType) {
        Class<?> propertyTypeClz = javaPropertyMap.get(jdbcType);
        return propertyTypeClz == null ? Object.class : propertyTypeClz;
    }
}
